﻿using log4net;
using SharpML.Api.Abstraction;
using SharpML.Api.Types;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SharpML.Adaptors.MNIST
{
    public class Digits : PatternData
    {
        // Simple logging pattern
        private static readonly ILog Log = LogManager.GetLogger( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType );

        public Digits( string path )
        {
            Log.Info( "Loading MNIST dataset." );

            TrainingData = LoadSegment( path, true );
            TestingData = new PatternData.DataItem[] { };
            //TestingData = LoadSegment( path, false );

            Log.InfoFormat( "Loaded {0} digits for training and {1} digits for testing.", TrainingData.Count(), TestingData.Count() );
        }

        private IEnumerable<PatternData.DataItem> LoadSegment( string path, bool forTraining )
        {
            var dataset = Utility.LoadFile( path, forTraining, 1000 ).Select( item => new PatternData.DataItem {
                Label = item.Label,
                Data = item.ImageData,
                Image = item.Image
            } );

            return dataset;
        }
    }
}
